package com.yxjx.duoxue.datamodel;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

public class DMCoupon extends DMObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7348292360084288575L;
	private int id;
	private int couponPrice;
	private String couponDes;
	private String couponName;
	private long limitOrderPrice;
	private boolean selected;
	private long startTime;
	private long endTime;
	private int couponId;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public boolean isSelected() {
		return selected;
	}
	public void setSelected(boolean selected) {
		this.selected = selected;
	}
	
	
	public static DMCoupon from(String str) {
		if (UIHelper.isEmpty(str)) {
			return null;
		}
		
		try {
			JSONObject jo = new JSONObject(str);
			DMCoupon item = new DMCoupon();
			item.setCouponDes(castString(jo,"couponDes"));
			item.setCouponName(castString(jo,"couponName"));
			item.setCouponPrice(castInteger(jo,"couponPrice"));
			item.setId(castInteger(jo,"id"));
			item.setLimitOrderPrice(castLong(jo,"limitOrderPrice"));
			item.setStartTime(castLong(jo,"startTime"));
			item.setEndTime(castLong(jo,"endTime"));
			item.setCouponId(castInteger(jo,"couponId"));
			return item;
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	@Override
	public String toString() {
		return "{ id = " + id + ",couponPrice = " + couponPrice
				+ ",couponDes = " + couponDes + ",couponName = " + couponName
				+ ",limitOrderPrice = " + limitOrderPrice + ",selected = "
				+ selected + ", startTime = " + startTime + ", endTime = "
				+ endTime + ", couponId = " + couponId + "}";
	}

	public int getCouponPrice() {
		return couponPrice;
	}
	public void setCouponPrice(int couponPrice) {
		this.couponPrice = couponPrice;
	}
	public String getCouponDes() {
		return couponDes;
	}
	public void setCouponDes(String couponDes) {
		this.couponDes = couponDes;
	}
	public String getCouponName() {
		return couponName;
	}
	public void setCouponName(String couponName) {
		this.couponName = couponName;
	}
	public long getLimitOrderPrice() {
		return limitOrderPrice;
	}
	public void setLimitOrderPrice(long limitOrderPrice) {
		this.limitOrderPrice = limitOrderPrice;
	}
	public long getStartTime() {
		return startTime;
	}
	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}
	public long getEndTime() {
		return endTime;
	}
	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}
	public int getCouponId() {
		return couponId;
	}
	public void setCouponId(int couponId) {
		this.couponId = couponId;
	}

}
